package com.ruoyi.web.controller.training;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.training.domain.TrainPlanPaperQuestion;
import com.ruoyi.training.service.ITrainPlanPaperQuestionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培训计划试卷题目Controller
 *
 * @author wng
 * @date 2024-08-04
 */
@RestController
@RequestMapping("/training/paperQuestion")
public class TrainPlanPaperQuestionController extends BaseController {
    @Resource
    private ITrainPlanPaperQuestionService trainPlanPaperQuestionService;

    /**
     * 查询培训计划试卷题目列表
     */
    @PreAuthorize("@ss.hasPermi('system:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(TrainPlanPaperQuestion trainPlanPaperQuestion) {
        startPage();
        List<TrainPlanPaperQuestion> list = trainPlanPaperQuestionService.selectTrainPlanPaperQuestionList(trainPlanPaperQuestion);
        return getDataTable(list);
    }

    /**
     * 导出培训计划试卷题目列表
     */
    @PreAuthorize("@ss.hasPermi('system:question:export')")
    @Log(title = "培训计划试卷题目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainPlanPaperQuestion trainPlanPaperQuestion) {
        List<TrainPlanPaperQuestion> list = trainPlanPaperQuestionService.selectTrainPlanPaperQuestionList(trainPlanPaperQuestion);
        ExcelUtil<TrainPlanPaperQuestion> util = new ExcelUtil<TrainPlanPaperQuestion>(TrainPlanPaperQuestion.class);
        util.exportExcel(response, list, "培训计划试卷题目数据");
    }

    /**
     * 获取培训计划试卷题目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(trainPlanPaperQuestionService.selectTrainPlanPaperQuestionById(id));
    }

    /**
     * 新增培训计划试卷题目
     */
    @PreAuthorize("@ss.hasPermi('system:question:add')")
    @Log(title = "培训计划试卷题目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainPlanPaperQuestion trainPlanPaperQuestion) {
        return toAjax(trainPlanPaperQuestionService.insertTrainPlanPaperQuestion(trainPlanPaperQuestion));
    }

    /**
     * 修改培训计划试卷题目
     */
    @PreAuthorize("@ss.hasPermi('system:question:edit')")
    @Log(title = "培训计划试卷题目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainPlanPaperQuestion trainPlanPaperQuestion) {
        return toAjax(trainPlanPaperQuestionService.updateTrainPlanPaperQuestion(trainPlanPaperQuestion));
    }

    /**
     * 删除培训计划试卷题目
     */
    @PreAuthorize("@ss.hasPermi('system:question:remove')")
    @Log(title = "培训计划试卷题目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(trainPlanPaperQuestionService.deleteTrainPlanPaperQuestionByIds(ids));
    }
}
